package com.lixiaoyi.emp.service.impl;

import com.lixiaoyi.emp.dao.IEmpManagerDao;
import com.lixiaoyi.emp.dao.impl.EmpManagerDaoImpl;
import com.lixiaoyi.emp.entity.EmpManager;
import com.lixiaoyi.emp.service.IEmpManagerService;
import com.lixiaoyi.emp.utils.DbUtils;

/**
 * @Author 李小毅
 * @Description
 * @Date 2022-05-12
 */

public class EmpManagerServiceImpl implements IEmpManagerService {

    //持有dao层对象
    private IEmpManagerDao empManagerDao = new EmpManagerDaoImpl();

    @Override
    public EmpManager login(String username, String password) {

        EmpManager empManager = null;

        try {
            //1.开启事务
            DbUtils.begin();
            //2.获取用户
            EmpManager temp = empManagerDao.select(username);
            //3.判断参数
            if (temp!=null){
                if (temp.getPassword().equals(password)){
                    empManager = temp;
                }
            }
            //4.提交
            DbUtils.commit();
        } catch (Exception e) {
            DbUtils.rollback();
            e.printStackTrace();
        }

        return empManager;
    }
}
